#include <bits/stdc++.h>
using namespace std;
char z[210][210];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}, n, m, a, b, flag, vis[210][210];
struct pp
{
    int x, y, s;
};
bool operator<(const pp &a, const pp &b)
{
    return a.s > b.s;
}
priority_queue<pp> q;
void bfs()
{
    pp p, h;
    p.x = a;
    p.y = b;
    p.s = 0;
    q.push(p);
    while (!q.empty())
    {
        p = q.top();
        q.pop();
        if (z[p.x][p.y] == 'a')
        {
            flag = 0;
            cout << p.s << endl;
            return;
        }
        for (int i = 0; i < 4; i++)
        {
            h.x = p.x + dx[i];
            h.y = p.y + dy[i];
            h.s = p.s + 1;
            if (h.x >= 0 && h.x < n && h.y >= 0 && h.y < m && !vis[h.x][h.y] && z[h.x][h.y] != '#')
            {
                if (z[h.x][h.y] == 'x')
                    h.s++;
                vis[h.x][h.y] = 1;
                q.push(h);
            }
        }
    }
}
int main()
{
    while (cin >> n >> m)
    {
        memset(vis, 0, sizeof(vis));
        flag = 1;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
            {
                cin >> z[i][j];
                if (z[i][j] == 'r')
                {
                    a = i;
                    b = j;
                }
            }
        bfs();
        if (flag)
            cout << "Poor ANGEL has to stay in the prison all his life.\n";
        while (!q.empty())
            q.pop();
    }
    return 0;
}
// https: //blog.csdn.net/JSMSG/article/details/79235224